package com.lemon.smartsafetynew.ui.fragment.patrol;

import android.os.Bundle;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolHistoryItemVo;
import com.lemon.smartsafetynew.net.services.SafePatrolServices;
import com.lemon.smartsafetynew.ui.activity.patrol.SafePatrolHistoryDetailActivity;
import com.lemon.smartsafetynew.ui.adapter.patrol.PatrolHistoryAdapter;
import com.lemon.smartsafetynew.util.constants.KeyConstants;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * Created by Andrew on 2017/10/31.
 */

public class SafePatrolHistoryNewFragment
        extends BasePullToRefreshFragment<SafePatrolHistoryItemVo, List<SafePatrolHistoryItemVo>>
        implements RecyclerTClickListener<SafePatrolHistoryItemVo> {

    private static String item_id;

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();

        Bundle bundle = getArguments();

        if(bundle != null) {
            if(bundle.containsKey(KeyConstants.KEY_SAFE_PATROL_ITEM_ID)) {
                item_id = bundle.getString(KeyConstants.KEY_SAFE_PATROL_ITEM_ID);
            }
        }
    }

    public static SafePatrolHistoryNewFragment newInstance(String item_id) {

        Bundle args = new Bundle();
        args.putString(KeyConstants.KEY_SAFE_PATROL_ITEM_ID, item_id);

        SafePatrolHistoryNewFragment fragment = new SafePatrolHistoryNewFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onPullRefresh() {

        LemonRequestParams params = new LemonRequestParams("");
        params.put("item_id", item_id);
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);

        SafePatrolServices
                .init()
                .getSafePatrolCheckItemHistoryList(RefreshType.REFRESH, params);
    }

    @Override
    public void onLoadMore() {

        LemonRequestParams params = new LemonRequestParams("");
        params.put("item_id", item_id);
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);

        SafePatrolServices
                .init()
                .getSafePatrolCheckItemHistoryList(RefreshType.LOAD_MORE, params);
    }

    @Override
    public void onItemClick(SafePatrolHistoryItemVo data, int position) {

        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_SAFE_PATROL_CHECK_ITEM_HISTORY_RESULT, data);
        UIHelper.showActivity(getmContext(), bundle, SafePatrolHistoryDetailActivity.class);

    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<SafePatrolHistoryItemVo> getLemonAdapter() {
        return new PatrolHistoryAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return KeyConstants.URL_GET_SAFE_PATROL_CHECK_ITEM_HISTORY_LIST;
    }
}
